package com.zjsd.sqeybusiness.controller;

import java.util.List;

import com.zjsd.sqeybusiness.dto.ProductCategoryDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zjsd.sqeybusiness.domain.ProductCategory;
import com.zjsd.sqeybusiness.service.IProductCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业产品分类Controller
 *
 * @author Zheng
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/jph/productCategory")
public class ProductCategoryController extends BaseController
{
    @Autowired
    private IProductCategoryService productCategoryService;

    /**
     * 查询企业产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductCategory productCategory)
    {
        startPage();
        List<ProductCategoryDTO> list = productCategoryService.selectProductCategoryList(productCategory);
        return getDataTable(list);
    }

    /**
     * 导出企业产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:export')")
    //@Log(title = "企业产品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductCategory productCategory)
    {
        List<ProductCategoryDTO> list = productCategoryService.selectProductCategoryList(productCategory);
        ExcelUtil<ProductCategoryDTO> util = new ExcelUtil<>(ProductCategoryDTO.class);
        return util.exportExcel(list, "productCategory");
    }

    /**
     * 获取企业产品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return AjaxResult.success(productCategoryService.selectProductCategoryById(categoryId));
    }

    /**
     * 新增企业产品分类
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:add')")
    //@Log(title = "企业产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductCategory productCategory)
    {
        return toAjax(productCategoryService.insertProductCategory(productCategory));
    }

    /**
     * 修改企业产品分类
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:edit')")
    //@Log(title = "企业产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductCategory productCategory)
    {
        return toAjax(productCategoryService.updateProductCategory(productCategory));
    }

    /**
     * 删除企业产品分类
     */
    @PreAuthorize("@ss.hasPermi('jph:productCategory:remove')")
    //@Log(title = "企业产品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(productCategoryService.deleteProductCategoryByIds(categoryIds));
    }
}
